package model

import "time"

// TableInfo 表信息
type TableInfo struct {
	TableName   string    `json:"table_name"`
	SchemaName  string    `json:"schema_name"`
	TableType   string    `json:"table_type"`
	Comment     string    `json:"comment,omitempty"`
	CreatedTime time.Time `json:"created_time,omitempty"`
}

// ColumnInfo 列信息
type ColumnInfo struct {
	TableName              string `json:"table_name"`
	ColumnName             string `json:"column_name"`
	DataType               string `json:"data_type"`
	IsNullable             string `json:"is_nullable"`
	ColumnDefault          string `json:"column_default,omitempty"`
	CharacterMaximumLength *int   `json:"character_maximum_length,omitempty"`
	NumericPrecision       *int   `json:"numeric_precision,omitempty"`
	NumericScale           *int   `json:"numeric_scale,omitempty"`
	Comment                string `json:"comment,omitempty"`
	OrdinalPosition        int    `json:"ordinal_position"`
}

// IndexInfo 索引信息
type IndexInfo struct {
	TableName  string `json:"table_name"`
	IndexName  string `json:"index_name"`
	ColumnName string `json:"column_name"`
	IsUnique   bool   `json:"is_unique"`
	IsPrimary  bool   `json:"is_primary"`
	IndexType  string `json:"index_type"`
}

// ConstraintInfo 约束信息
type ConstraintInfo struct {
	TableName        string `json:"table_name"`
	ConstraintName   string `json:"constraint_name"`
	ConstraintType   string `json:"constraint_type"`
	ColumnName       string `json:"column_name,omitempty"`
	ReferencedTable  string `json:"referenced_table,omitempty"`
	ReferencedColumn string `json:"referenced_column,omitempty"`
}

// DatabaseSchema 数据库模式
type DatabaseSchema struct {
	Tables      []TableInfo      `json:"tables"`
	Columns     []ColumnInfo     `json:"columns"`
	Indexes     []IndexInfo      `json:"indexes"`
	Constraints []ConstraintInfo `json:"constraints"`
	Generated   time.Time        `json:"generated"`
}

// SchemaDiff 模式差异
type SchemaDiff struct {
	MissingTables      []string         `json:"missing_tables"`
	ExtraTables        []string         `json:"extra_tables"`
	MissingColumns     []ColumnInfo     `json:"missing_columns"`
	ExtraColumns       []ColumnInfo     `json:"extra_columns"`
	ModifiedColumns    []ColumnDiff     `json:"modified_columns"`
	MissingIndexes     []IndexInfo      `json:"missing_indexes"`
	ExtraIndexes       []IndexInfo      `json:"extra_indexes"`
	MissingConstraints []ConstraintInfo `json:"missing_constraints"`
	ExtraConstraints   []ConstraintInfo `json:"extra_constraints"`
}

// ColumnDiff 列差异
type ColumnDiff struct {
	TableName  string     `json:"table_name"`
	ColumnName string     `json:"column_name"`
	Old        ColumnInfo `json:"old"`
	New        ColumnInfo `json:"new"`
	Changes    []string   `json:"changes"`
}

// DDLOperation DDL操作
type DDLOperation struct {
	ID         int64      `json:"id"`
	Operation  string     `json:"operation"`
	TableName  string     `json:"table_name"`
	SQL        string     `json:"sql"`
	Status     string     `json:"status"`
	Error      string     `json:"error,omitempty"`
	ExecutedAt *time.Time `json:"executed_at,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
}
